package com.example.controller;

import com.example.common.response.Result;
import com.example.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/files")
public class FileController {
    @Autowired
    private FileService fileService;

    @PostMapping("/upload/avatar")
    public Result<String> uploadAvatar(@RequestParam("file") MultipartFile file) {
        String filePath = fileService.uploadFile(file, "avatars");
        return Result.success(filePath);
    }

    @PostMapping("/upload/post")
    public Result<String> uploadPostImage(@RequestParam("file") MultipartFile file) {
        String filePath = fileService.uploadFile(file, "posts");
        return Result.success(filePath);
    }
} 